package org.openmore.consumer.controller.api;

import io.swagger.annotations.*;
import org.openmore.consumer.annotation.TokenAuthCheck;
import org.openmore.consumer.controller.common.BaseController;
import org.openmore.consumer.dto.common.BaseResponse;
import org.openmore.consumer.dto.common.OperateLogDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;

/**
 * THIS IS AUTO GENERATED SOURCE CODE
 * Created by org.openmore
 * on 2018-08-22
 */
@Api(value = "/OperateLog", tags = "", description = "操作日志")
@RequestMapping(value = "/api/operateLog", produces = {APPLICATION_JSON_UTF8_VALUE})
@RestController
public class OperateLogController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private OperateLogController operateLogService;

    @TokenAuthCheck
    @ApiOperation(value = "分页返回所有数据", response = OperateLogDto.class, responseContainer = "List")
    @ApiResponses(value = {@ApiResponse(code = 400, message = "请求失败：找不到id={id}的", response = OperateLogDto.class)})
    @RequestMapping(method = RequestMethod.GET, value = "/query")
    public BaseResponse selectAllByPage(@RequestParam(required = false, defaultValue = "0") @ApiParam(value = "操作人姓名") String name,
                                        @RequestParam(required = false, defaultValue = "0") @ApiParam(value = "开始时间") Date startTime,
                                        @RequestParam(required = false, defaultValue = "0") @ApiParam(value = "结束时间") Date endTime,
                                        @RequestParam(required = false, defaultValue = "0") @ApiParam(value = "分页第几页") Integer pageNum,
                                        @RequestParam(required = false, defaultValue = "0") @ApiParam(value = "每页多少记录") Integer pageSize) {
        logger.debug(">> query");
        return operateLogService.selectAllByPage(name, startTime, endTime, pageNum, pageSize);
    }

    @TokenAuthCheck
    @ApiOperation(value = "检索操作日志列表", response = OperateLogDto.class, responseContainer = "List")
    @ApiResponses(value = {@ApiResponse(code = 400, message = "请求失败：找不到id={id}的", response = BaseResponse.class)})
    @RequestMapping(method = RequestMethod.GET, value = "/search")
    public BaseResponse searchOperate(@RequestParam(required = false) @ApiParam(value = "员工用户名") String staffName,
                                      @RequestParam(required = false) @ApiParam(value = "时间左边界 ") Date startTime,
                                      @RequestParam(required = false) @ApiParam(value = "时间右边界 ") Date endTime,
                                      @RequestParam(required = false, defaultValue = "1") @ApiParam(value = "分页第几页") Integer pageNum,
                                      @RequestParam(required = false, defaultValue = "10") @ApiParam(value = "每页多少记录") Integer pageSize) {
        logger.debug(">> search");
        return operateLogService.searchOperate(staffName, startTime, endTime, pageNum, pageSize);
    }

    @TokenAuthCheck
    @ApiOperation(value = "根据id获取信息", response = OperateLogDto.class)
    @ApiResponses(value = {@ApiResponse(code = 400, message = "请求失败：找不到id={id}的", response = BaseResponse.class)})
    @RequestMapping(method = RequestMethod.GET, value = "/{id}")
    public BaseResponse getOperateLogById(@PathVariable @ApiParam(required = true, value = "id") String id) {
        logger.debug(">> getOperateLogById");
        return operateLogService.getOperateLogById(id);
    }

    @ApiOperation(value = "保存日志", response = OperateLogDto.class)
    @ApiResponses(value = {@ApiResponse(code = 400, message = "请求失败：找不到id={id}的", response = BaseResponse.class)})
    @RequestMapping(method = RequestMethod.POST, consumes = {APPLICATION_JSON_UTF8_VALUE})
    public BaseResponse insertLog(@RequestBody @ApiParam(value = "日志信息") OperateLogDto operateLogDto) {
        logger.debug(">> insertLog");
       return operateLogService.insertLog(operateLogDto);
    }
}




